package Environment;

/**
 * Creates a boundary that act as walls. When moving entities hit the walls, 
 * they bounce off at an appropriate ankle. 
 * 
 * @author Ga-Young Joung and Perry Zheng
 */

import individual.*;

import java.awt.Dimension;
import java.util.ArrayList;

import utilities.Vector;
import view.Canvas;

public class WallBoundary implements Boundary {

	private Environment myEnvironment;

	/**
	 * 
	 * @param environment - the environment to which the boundary is supposed to enclose
	 */
	public WallBoundary(Environment environment) {
		myEnvironment = environment;
	}

	/**
	 * Return the new Position and new Velocity of the object when a moving
	 * entity hits the boundary
	 * @param center  the current center of the object
	 * @param velocity  the current velocity of the moving object
	 * @param sizeOfEntity  the size (radius, for instance) of the moving object
	 * @return - The new position and velocity of the moving object after the 
	 * moving entity hits the boundary. 
	 */
	public ArrayList<Vector> getNewPositionAndVelocity(Vector center,
			Vector velocity, Dimension sizeOfEntity) {
		Vector newVelocity = new Vector(velocity);
		Vector nextCenter = center.add(velocity);
		Vector newCenter = new Vector(nextCenter);
		Dimension size = myEnvironment.getSize();
		if (nextCenter.y - sizeOfEntity.height - velocity.y < 0
				|| nextCenter.y + sizeOfEntity.height - velocity.y > size.height) {
			newVelocity.y *= -1;
		}

		if (nextCenter.x - sizeOfEntity.width + velocity.x < 0
				|| nextCenter.x + sizeOfEntity.width + velocity.x > size.width) {
			newVelocity.x *= -1;
		}
		newCenter = center.add(newVelocity);
		ArrayList<Vector> list = new ArrayList<Vector>();
		list.add(newVelocity);
		list.add(newCenter);
		return list;
	}
}
